import axios from 'axios';

// 创建axios实例，指向后端API地址
const apiClient = axios.create({
  baseURL: 'http://localhost:8888/api',
  headers: {
    'Content-Type': 'application/json',
  },
});

// 房屋相关API方法
export const houseService = {
  // 获取所有房屋列表
  getAllHouses: async () => {
    const response = await apiClient.get('/houses');
    return response.data;
  },

  // 获取单个房屋详情
  getHouseById: async (id) => {
    const response = await apiClient.get(`/houses/${id}`);
    return response.data;
  },

  // 创建新房屋
  createHouse: async (houseData) => {
    const response = await apiClient.post('/houses', houseData);
    return response.data;
  },

  // 更新房屋信息
  updateHouse: async (id, houseData) => {
    const response = await apiClient.put(`/houses/${id}`, houseData);
    return response.data;
  },

  // 删除房屋
  deleteHouse: async (id) => {
    await apiClient.delete(`/houses/${id}`);
    return true;
  },
};

export default houseService;